package com.u3k.mid;

import android.app.ActivityManager;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Environment;
import android.os.StatFs;
import android.os.SystemClock;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import com.u3k.app.mid.utils.common.Util;
import com.u3k.app.mid.utils.statistics.StatisticsManager;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.Locale;
import org.json.JSONObject;

public class aw {
    private Context A;
    public String a;
    public String b;
    public String c;
    public String d;
    public String e;
    public int f;
    public String g;
    public String h = aq.a();
    public String i;
    public String j;
    public int k;
    public int l;
    public int m;
    public String n;
    public String o;
    public String p;
    public String q;
    public String r;
    public String s;
    public String t;
    public long u;
    public long v;
    public long w;
    public String x;
    public String y;
    public String z;

    public aw(Context context, boolean z) {
        int i = 1;
        this.A = context;
        String[] k = k();
        this.a = k[1];
        this.i = k[2];
        this.j = k[3];
        if (aq.c(context)) {
            k = c(this.A);
            this.b = k[0];
            this.s = k[1];
            this.c = k[2];
            this.t = k[3];
            this.d = d(this.A);
            if (TextUtils.isEmpty(this.d)) {
                this.d = "";
            }
        } else {
            this.b = "";
            this.s = "";
            this.c = "";
            this.t = "";
            this.d = "";
        }
        this.e = h()[0];
        this.f = i();
        this.g = j();
        this.l = l(this.A);
        this.m = m(this.A);
        if (!Util.isRootSystem()) {
            i = 0;
        }
        this.k = i;
        this.n = l();
        this.q = c();
        this.p = "";
        this.o = "0x0";
        this.p = "";
        this.q = m();
        this.r = null;
        this.u = d();
        this.v = e()[0];
        this.w = g()[0];
        this.x = g(this.A) + "x" + h(this.A);
        this.y = k(this.A);
        float i2 = i(this.A);
        float j = j(this.A);
        this.z = String.valueOf(Math.sqrt((double) ((i2 * i2) + (j * j))));
    }

    public static String a(Context context) {
        try {
            return Secure.getString(context.getContentResolver(), "android_id");
        } catch (Exception e) {
            StatisticsManager.getInstance().logException(ae.a(), e);
            return "";
        }
    }

    public static String b(Context context) {
        try {
            String str = (String) bb.b(context, "gaid", "");
            if (!TextUtils.isEmpty(str)) {
                return str;
            }
            ah a = af.a(context);
            if (a != null) {
                str = a.a();
                bb.a(context, "gaid", str);
                return str;
            }
            return "";
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
        }
    }

    public static String c() {
        return Locale.getDefault().getLanguage();
    }

    public static String[] c(Context context) {
        String[] strArr = new String[]{"", "", "", ""};
        if (aq.c(context)) {
            try {
                TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
                strArr[0] = telephonyManager.getSubscriberId();
                strArr[1] = telephonyManager.getLine1Number();
            } catch (Exception e) {
                LogUtils.a("Phoneinfo", e);
                StatisticsManager.getInstance().logException(ae.a(), e);
                return strArr;
            }
        }
        return strArr;
    }

    public static long d() {
        Exception e;
        long j = 0;
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader("/proc/meminfo"), 8192);
            String readLine = bufferedReader.readLine();
            if (readLine != null) {
                j = Long.parseLong(readLine.replaceAll("[a-z]|[A-Z]|:| ", "").trim()) * 1024;
            }
            try {
                bufferedReader.close();
            } catch (Exception e2) {
                e = e2;
                LogUtils.a("Phoneinfo", e);
                StatisticsManager.getInstance().logException(ae.a(), e);
                return j;
            }
        } catch (Exception e3) {
            e = e3;
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
            return j;
        }
        return j;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static java.lang.String d(android.content.Context r4) {
        /*
        r1 = com.u3k.mid.aq.a(r4);	 Catch:{ Exception -> 0x0026 }
        if (r1 == 0) goto L_0x000e;
    L_0x0006:
        r0 = "";
        r0 = r0.equals(r1);	 Catch:{ Exception -> 0x003b }
        if (r0 == 0) goto L_0x0025;
    L_0x000e:
        r0 = com.u3k.mid.aq.c(r4);	 Catch:{ Exception -> 0x003b }
        if (r0 == 0) goto L_0x0025;
    L_0x0014:
        r0 = "phone";
        r0 = r4.getSystemService(r0);	 Catch:{ Exception -> 0x003b }
        r0 = (android.telephony.TelephonyManager) r0;	 Catch:{ Exception -> 0x003b }
        r1 = r0.getDeviceId();	 Catch:{ Exception -> 0x003b }
        r0 = "sp_cache_read_imei";
        com.u3k.mid.bb.a(r4, r0, r1);	 Catch:{ Exception -> 0x0039 }
    L_0x0025:
        return r1;
    L_0x0026:
        r0 = move-exception;
        r1 = 0;
    L_0x0028:
        r2 = "Phoneinfo";
        com.u3k.mid.au.a(r2, r0);
        r2 = com.u3k.app.mid.utils.statistics.StatisticsManager.getInstance();
        r3 = com.u3k.mid.ae.a();
        r2.logException(r3, r0);
        goto L_0x0025;
    L_0x0039:
        r0 = move-exception;
        goto L_0x0028;
    L_0x003b:
        r0 = move-exception;
        goto L_0x0028;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.u3k.mid.aw.d(android.content.Context):java.lang.String");
    }

    public static String e(Context context) {
        String str;
        Exception exception;
        Exception e;
        LogUtils.a("PhoneInfo", "getImeiInfoNoCache");
        try {
            str = (String) bb.b(context, "sp_cache_read_imei", "");
            try {
                LogUtils.a("PhoneInfo", "getImeiInfoNoCache---imei>>>" + str);
                if (str == null || "".equals(str)) {
                    if (aq.c(context)) {
                        str = ((TelephonyManager) context.getSystemService("phone")).getDeviceId();
                        bb.a(context, "sp_cache_read_imei", str);
                    } else {
                        str = "";
                    }
                }
            } catch (Exception e2) {
                exception = e2;
                str = str;
                e2 = exception;
                LogUtils.LogError("PhoneInfo", "Phoneinfo", e2);
                StatisticsManager.getInstance().logException(ae.a(), e2);
                LogUtils.a("PhoneInfo", "getImeiInfoNoCache--aaaaa-imei>>>" + str);
                if (TextUtils.isEmpty(str)) {
                    str = Util.getServImei(context);
                }
                LogUtils.a("PhoneInfo", "getImeiInfoNoCache--bbbbb-imei>>>" + str);
                return str;
            }
        } catch (Exception e3) {
            exception = e3;
            str = null;
            e2 = exception;
            LogUtils.LogError("PhoneInfo", "Phoneinfo", e2);
            StatisticsManager.getInstance().logException(ae.a(), e2);
            LogUtils.a("PhoneInfo", "getImeiInfoNoCache--aaaaa-imei>>>" + str);
            if (TextUtils.isEmpty(str)) {
                str = Util.getServImei(context);
            }
            LogUtils.a("PhoneInfo", "getImeiInfoNoCache--bbbbb-imei>>>" + str);
            return str;
        }
        LogUtils.a("PhoneInfo", "getImeiInfoNoCache--aaaaa-imei>>>" + str);
        if (TextUtils.isEmpty(str)) {
            str = Util.getServImei(context);
        }
        LogUtils.a("PhoneInfo", "getImeiInfoNoCache--bbbbb-imei>>>" + str);
        return str;
    }

    public static long[] e() {
        long[] jArr = new long[]{0, 0};
        jArr[0] = f();
        StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
        jArr[1] = ((((long) statFs.getBlockSize()) * ((long) statFs.getAvailableBlocks())) / 1024) / 1024;
        return jArr;
    }

    public static long f() {
        StatFs statFs = new StatFs(Environment.getDataDirectory().getPath());
        return ((((long) statFs.getBlockCount()) * ((long) statFs.getBlockSize())) / 1024) / 1024;
    }

    public static String f(Context context) {
        String[] strArr = new String[]{"", ""};
        try {
            if (!av.b(context, "android.permission.ACCESS_WIFI_STATE")) {
                return strArr[0];
            }
            WifiInfo connectionInfo = ((WifiManager) context.getSystemService("wifi")).getConnectionInfo();
            if (connectionInfo.getMacAddress() != null) {
                strArr[0] = connectionInfo.getMacAddress();
            }
            strArr[1] = o();
            return strArr[0];
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
        }
    }

    public static int g(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
        return displayMetrics.widthPixels;
    }

    public static long[] g() {
        long[] jArr = new long[]{0, 0};
        try {
            if ("mounted".equals(Environment.getExternalStorageState())) {
                StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
                long blockSize = (long) statFs.getBlockSize();
                long availableBlocks = (long) statFs.getAvailableBlocks();
                jArr[0] = ((((long) statFs.getBlockCount()) * blockSize) / 1024) / 1024;
                jArr[1] = ((blockSize * availableBlocks) / 1024) / 1024;
            }
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
        }
        return jArr;
    }

    public static int h(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
        return displayMetrics.heightPixels;
    }

    public static String[] h() {
        int i = 2;
        String[] strArr = new String[]{"", ""};
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader("/proc/cpuinfo"), 8192);
            String readLine = bufferedReader.readLine();
            if (readLine != null) {
                String[] split = readLine.split("\\s+");
                while (i < split.length) {
                    strArr[0] = strArr[0] + split[i] + " ";
                    i++;
                }
            }
            String readLine2 = bufferedReader.readLine();
            if (readLine2 != null) {
                strArr[1] = strArr[1] + readLine2.split("\\s+")[2];
            }
            bufferedReader.close();
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
        }
        return strArr;
    }

    public static float i(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
        return ((float) displayMetrics.widthPixels) / (displayMetrics.density * 160.0f);
    }

    public static int i() {
        try {
            return new File("/sys/devices/system/cpu/").listFiles(new ax()).length;
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
            return 1;
        }
    }

    public static float j(Context context) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
        return ((float) displayMetrics.heightPixels) / (displayMetrics.density * 160.0f);
    }

    public static String j() {
        String str = "";
        try {
            InputStream inputStream = new ProcessBuilder(new String[]{"/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"}).start().getInputStream();
            byte[] bArr = new byte[24];
            while (inputStream.read(bArr) != -1) {
                str = str + new String(bArr);
            }
            inputStream.close();
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
            str = "N/A";
        }
        return str.trim();
    }

    public static String k(Context context) {
        return ((ActivityManager) context.getSystemService("activity")).getDeviceConfigurationInfo().getGlEsVersion();
    }

    public static String[] k() {
        String[] strArr = new String[]{"", "", "", ""};
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader("/proc/version"), 8192);
            String readLine = bufferedReader.readLine();
            if (readLine != null) {
                strArr[0] = readLine.split("\\s+")[2];
            }
            bufferedReader.close();
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
        }
        strArr[1] = VERSION.RELEASE;
        strArr[2] = Build.MODEL;
        strArr[3] = Build.DISPLAY;
        return strArr;
    }

    public static int l(Context context) {
        try {
            if (!av.b(context, "android.permission.ACCESS_NETWORK_STATE")) {
                return -1;
            }
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
            if (activeNetworkInfo == null) {
                return -1;
            }
            int subtype;
            int type = activeNetworkInfo.getType();
            if (type == 0) {
                subtype = activeNetworkInfo.getSubtype();
                subtype = (subtype == 2 || subtype == 1) ? 2 : subtype == 13 ? 4 : 3;
            } else {
                if (type == 1) {
                    subtype = 1;
                }
                subtype = -1;
            }
            return subtype;
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
        }
    }

    public static String l() {
        Enumeration networkInterfaces;
        Object stringBuffer;
        try {
            networkInterfaces = NetworkInterface.getNetworkInterfaces();
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            networkInterfaces = null;
        }
        while (networkInterfaces != null && networkInterfaces.hasMoreElements()) {
            NetworkInterface networkInterface = (NetworkInterface) networkInterfaces.nextElement();
            try {
                String name = networkInterface.getName();
                if (name != null && name.startsWith("wlan")) {
                    byte[] hardwareAddress;
                    try {
                        hardwareAddress = VERSION.SDK_INT >= 9 ? networkInterface.getHardwareAddress() : null;
                    } catch (Exception e2) {
                        LogUtils.a("Phoneinfo", e2);
                        StatisticsManager.getInstance().logException(ae.a(), e2);
                        hardwareAddress = null;
                    }
                    if (hardwareAddress == null) {
                        continue;
                    } else if (hardwareAddress.length > 0) {
                        StringBuffer stringBuffer2 = new StringBuffer();
                        int length = hardwareAddress.length;
                        for (int i = 0; i < length; i++) {
                            stringBuffer2.append(String.format("%02X:", new Object[]{Byte.valueOf(hardwareAddress[i])}));
                        }
                        if (stringBuffer2.length() > 0) {
                            stringBuffer2.deleteCharAt(stringBuffer2.length() - 1);
                        }
                        stringBuffer = stringBuffer2.toString();
                        return TextUtils.isEmpty(stringBuffer) ? "" : stringBuffer;
                    }
                }
            } catch (Exception e22) {
                LogUtils.a("Phoneinfo", e22);
                StatisticsManager.getInstance().logException(ae.a(), e22);
            }
        }
        stringBuffer = null;
        if (TextUtils.isEmpty(stringBuffer)) {
        }
    }

    public static int m(Context context) {
        if (!av.b(context, "android.permission.ACCESS_NETWORK_STATE")) {
            return 0;
        }
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
        if (activeNetworkInfo != null) {
            activeNetworkInfo.isConnected();
            if (activeNetworkInfo.isRoaming()) {
                return 1;
            }
        }
        return 0;
    }

    private String n() {
        try {
            b(this.A);
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
        }
        return "";
    }

    private static String o() {
        long elapsedRealtime = SystemClock.elapsedRealtime() / 1000;
        if (elapsedRealtime == 0) {
            elapsedRealtime = 1;
        }
        return ((int) (elapsedRealtime / 3600)) + " h" + ((int) ((elapsedRealtime / 60) % 60)) + " m";
    }

    public JSONObject a() {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("androidVer", this.a);
            jSONObject.put("imsi", this.b);
            jSONObject.put("imsi2", this.c);
            jSONObject.put("imei", this.d);
            jSONObject.put("cpu", this.e);
            jSONObject.put("cpuCore", this.f);
            jSONObject.put("cpuFreq", this.g);
            jSONObject.put("man", this.h);
            jSONObject.put("model", this.i);
            jSONObject.put("rooted", this.k);
            jSONObject.put("roam", this.m);
            jSONObject.put("net", this.l);
            jSONObject.put("mac", this.n);
            jSONObject.put("location", this.o);
            jSONObject.put("display", this.j);
            jSONObject.put("lang", this.q);
            jSONObject.put("smc_center", this.r);
            jSONObject.put("tel", this.s);
            jSONObject.put("tel2", this.t);
            jSONObject.put("ram", this.u);
            jSONObject.put("inStorage", this.v);
            jSONObject.put("exStorage", this.w);
            jSONObject.put("resolution", this.x);
            jSONObject.put("opengles", this.y);
            jSONObject.put("aid", b());
            jSONObject.put("gaid", n());
        } catch (Exception e) {
            LogUtils.a("Phoneinfo", e);
            StatisticsManager.getInstance().logException(ae.a(), e);
        }
        return jSONObject;
    }

    public String b() {
        return Secure.getString(this.A.getContentResolver(), "android_id");
    }

    public String m() {
        Locale locale = Locale.getDefault();
        return String.format("%s-%s", new Object[]{locale.getLanguage(), locale.getCountry()});
    }
}
